﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;

namespace Eleanor.DAL
{
    public class SettingDAL : DALBase
    {
        public int Insert(dynamic setting)
        {
            var command = DefaultContext
                    .Sql("SettingInsert")
                    .CommandType(DbCommandTypes.StoredProcedure)
                    .Parameter("value", setting.Value)
                    .ParameterOut<int>("SettingId");
            command.Execute();
            return command.ParameterValue<int>("SettingId");
        }

        public int Update(dynamic setting)
        {
            var command = DefaultContext
                    .Sql("SettingUpdate")
                    .CommandType(DbCommandTypes.StoredProcedure)
                    .Parameter("value", setting.Value)
                    .Parameter("SettingId", setting.SettingId);
            return command.Execute();
        }

        public dynamic Select(int settingId)
        {
            var command = DefaultContext
                    .Sql("SettingSelectOne")
                    .CommandType(DbCommandTypes.StoredProcedure)
                    .Parameter("SettingId", settingId);
            return command.QuerySingle<dynamic>();
        }

        public List<dynamic> SelectAll()
        {
            var command = DefaultContext
                        .Sql("SettingSelectALL")
                        .CommandType(DbCommandTypes.StoredProcedure);
            return command.QueryMany<dynamic>();
        }

        public dynamic Delete(int settingId)
        {
            var command = DefaultContext
                          .Sql("SettingDelete")
                          .CommandType(DbCommandTypes.StoredProcedure)
                          .Parameter("SettingId", settingId);
            return command.Execute();
        }
    }
}
